package com.bfd.archetype.component;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.bfd.archetype.constants.DBFieldConstants;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;

/**
 * @program: MyMetaObjectHandler
 * @description: 用于在创建更新的时候自动插入数据
 * @author: guangyu.you
 * @create: 2020-10-15 16:39
 **/
@Configuration
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        boolean flag = metaObject.hasSetter(DBFieldConstants.CREATETIME);
        if (flag) {
            strictInsertFill(metaObject,DBFieldConstants.CREATETIME, LocalDateTime.class,LocalDateTime.now());
        }

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        boolean flag = metaObject.hasSetter(DBFieldConstants.UPDATETIME);
        if (flag) {
            strictInsertFill(metaObject,DBFieldConstants.UPDATETIME, LocalDateTime.class,LocalDateTime.now());
        }
    }


}
